package cn.sdstudio.service.impl;

import cn.sdstudio.constants.SystemConstants;
import cn.sdstudio.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @author Zyq
 * @version 1.0
 * @date 2025/4/22 周二
 */

@Service
public class MailServiceImpl implements MailService {

    @Autowired
    private JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String from;

    @Value("${spring.application.name}")
    private String senderName;


    @Override
    public Boolean sendCode(String email, String code) {
        SimpleMailMessage message = new SimpleMailMessage();

        message.setFrom(from);
        message.setTo(email);
        message.setSubject(senderName+SystemConstants.EMAIL_SUBJECT);
        message.setText("您的验证码是：" + code + "，有效期5分钟，请勿泄露。");
        mailSender.send(message);

        return true;
    }


}
